package com.woniu.platform.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniu.platform.entity.PlatformOrderForm;
import com.woniu.platform.mapper.PlatformOrderFormMapper;
import com.woniu.platform.service.PlatformOrderFormService;
import com.woniu.util.utils.HttpResult;
import com.woniu.util.utils.RequestResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PlatformOrderFormServiceImpl implements PlatformOrderFormService {

    @Autowired(required = false)
    private PlatformOrderFormMapper orderFormMapper;
    @Override
    public HttpResult insertOrderFormAc(PlatformOrderForm platformOrderForm) {
        int re = orderFormMapper.insert(platformOrderForm);

        if(re>0){
            return new HttpResult().ok();
        }else{
            return new HttpResult().fail();
        }
    }

    @Override
    public HttpResult updateOrderForm(PlatformOrderForm platformOrderForm) {
        int re = orderFormMapper.updateById(platformOrderForm);
        if (re > 0) {
            return new HttpResult().ok();
        }else{
            return new HttpResult().fail();
        }
    }

    @Override
    public HttpResult queryOrderForm(RequestResult<PlatformOrderForm> requestResult) {
        PageHelper.startPage(requestResult.getPageNum(), requestResult.getPageSize());
        List<PlatformOrderForm> list = orderFormMapper.queryPlatformOrderForm(requestResult.getData().getPlatformShop().getGoodName(),
                                                                    requestResult.getData().getCustomer().getRealName(),
                                                                    requestResult.getData().getOrderState());
        PageInfo pageInfo = new PageInfo(list);
        return new HttpResult().ok(pageInfo);
    }

    @Override
    public HttpResult queryOrderFormByCustomerId(String customerId) {
        PlatformOrderForm platformOrderForm = orderFormMapper.queryPlatformOrderFormByCustomerId(customerId);
        if(platformOrderForm == null){
            return new HttpResult().fail();
        }else{
            return new HttpResult().ok(platformOrderForm);
        }
    }
}
